/**
 * @author yuliang
 *
 */
package com.xuhai.libms.daoImpl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.xuhai.libms.dao.BookTypeDao;
import com.xuhai.libms.entity.BookType;

public class BookTypeDaoImpl extends HibernateDaoSupport implements BookTypeDao{

	public void insert(BookType bookType) {
		super.getHibernateTemplate().save(bookType);
	}

	public void modify(BookType bookType) {
		super.getHibernateTemplate().update(bookType);
		
	}

	public void remove(BookType bookType) {
		super.getHibernateTemplate().delete(bookType);
	}

	public List<BookType> show() {
		return (List)super.getHibernateTemplate().find("from BookType");
	}

	public BookType show(int id) {
		return (BookType)super.getHibernateTemplate().get(BookType.class, id);
	}

	public List<BookType> showByPage(BookType bookType,int start, int end) {
		String sql = "from BookType b where 1=1";
		if(bookType.getTypeName()!=""&&bookType.getTypeName()!=null){
			sql+=" and b.typeName="+"'"+bookType.getTypeName()+"'";
		}
		if(bookType.getP_id()!=-1){
			sql+=" and b.p_id="+bookType.getP_id();
		}
		return (List)super.getHibernateTemplate().find(sql).subList(start, end);
	}

	public List<BookType> showByPid(int p_id) {
		return (List)super.getHibernateTemplate().find("from BookType where p_id="+p_id);
	}

	public int getSize(BookType bookType) {
		String sql = "from BookType b where 1=1";
		if(bookType.getTypeName()!=""&&bookType.getTypeName()!=null){
			sql+=" and b.typeName="+"'"+bookType.getTypeName()+"'";
		}
		if(bookType.getP_id()!=-1){
			sql+=" and b.p_id="+bookType.getP_id();
		}
		return super.getHibernateTemplate().find(sql).size();
	}

}
